<template>
<!-- 首页头部组件 -->
  <div class="home-header" :class="{'active' : active}">
    <div class="ico">
      <i class="icon icon-fenlei" @click="$router.push('/category')"></i>
    </div>
    <div class="content">
      <span class="G">G</span>
      <i class="icon icon-wxbsousuotuiguang"></i>
      <span class="text">家电返场同价11.11</span>
    </div>
    <div class="login">
      <router-link to="/login">
        <span v-show="!$store.getters.getIsLogin">登录</span>
        <i v-show="$store.getters.getIsLogin" class="icon icon-wode"></i>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
      active: false
    }
  },
  mounted() {
    // 添加滚动事件
    window.addEventListener('scroll', this.pageScroll)
  },
  methods: {
    pageScroll() {
      // 获取滚动距离
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      scrollTop > 100 ? this.active = true : this.active = false
    }
  }
}
</script>

<style lang="scss" scoped>
  .home-header{
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    height: 100px;
    padding: 0 20px;
    justify-content: space-between;
    align-items: center;
    z-index: 1;
    box-sizing: border-box;
  }
  .content{
    display: flex;
    align-items: center;
    width: 74%;
    height: 40px;
    background-color: white;
    padding: 10px 0;
    border-radius: 50px;
  }
  .G{
    padding: 0 20px; 
    font-size: 40px;
    font-weight: 600;
    border-right: 1px solid #666;
    color: red;
  }
  .icon-fenlei{
    font-size: 50px;
    color: white;
  }
  .icon-wxbsousuotuiguang{
    font-size: 34px;
    padding: 0 20px;
  }
  .text{
    font-size: 24px;
    color: #666;
  }
  .login a{
    font-size: 30px;
    color: white;
  }
  .icon-wode{
    font-size: 48px;
  }
  .active{
    background-color: red;
  }
</style>